package com.module.sysconfig.controller;


import java.io.IOException;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.module.sysconfig.entity.Cyyjpz;
import com.module.sysconfig.entity.Zdb;
import com.module.sysconfig.service.CyyjpzService;
import com.support.helper.AjaxHelper;
import com.support.util.StringUtils;
import com.support.web.ControllerSupport;
/**
 * 常用意见表
 * @author 吕乐帅
 *
 */
@Controller
@Scope(value = "prototype")
@RequestMapping("/sysconfig/cyyjpz")
public class CyyjpzController extends ControllerSupport {
	 private final Logger logger = LoggerFactory.getLogger(this.getClass());
	 
	/* @Autowired
	 private ZdbService zdbService;
	 */
	@Autowired
	 private CyyjpzService cyyjpzService;
	 
	

	/**
	 * 新增常用意见数据
	 * @throws IOException
	 */
	@RequestMapping("/saveCyyjpz")
	 public void saveCyyjpz() throws IOException
	 {
		 try{
			 
			 
			 Map<String, String>  paramsMap =  this.getParamsMap();
			 	Cyyjpz cyyjpz=new Cyyjpz();
				String YWLXID = paramsMap.get("YWLXID");
				String YWLXMC = paramsMap.get("YWLXMC");
				String MS = paramsMap.get("MS");
				String QT = paramsMap.get("QT");
				String CYYJ = paramsMap.get("CYYJ");
				String SYZID = paramsMap.get("SYZID");
				String SZJDID = paramsMap.get("SZJDID");
				String JDMC = paramsMap.get("JDMC");
				String CJR = paramsMap.get("CJR");
				String CJRMC = paramsMap.get("CJRMC");
				String ZHXGR = paramsMap.get("ZHXGR");
				String ZHXGRMC = paramsMap.get("ZHXGRMC");
				String BZ1 = paramsMap.get("BZ1");
				String BZ2 = paramsMap.get("BZ2");
				String BZ3 = paramsMap.get("BZ3");
				String BZ4 = paramsMap.get("BZ4");
				
				cyyjpz.setYwlxid(YWLXID ==null ? "": YWLXID);
				cyyjpz.setYwlxmc(YWLXMC ==null ? "": YWLXMC);
				cyyjpz.setMs(MS ==null ? "": MS);
				cyyjpz.setQt(QT ==null ? "": QT);
				cyyjpz.setCyyj(CYYJ ==null ? "": CYYJ);
				cyyjpz.setSyzid(SYZID ==null ? "": SYZID);
				cyyjpz.setSzjdid(SZJDID ==null ? "": SZJDID);
				cyyjpz.setJdmc(JDMC ==null ? "": JDMC);
				cyyjpz.setCjr(CJR == null ? "":CJR);
				cyyjpz.setCjrmc(CJRMC == null ? "":CJRMC);
				cyyjpz.setZhxgr(ZHXGR == null ? "":ZHXGR);
				cyyjpz.setZhxgrmc(ZHXGRMC == null ? "":ZHXGRMC);
				cyyjpz.setSfhf(1);
				cyyjpz.setBz1(BZ1 == null ? "":BZ1);
				cyyjpz.setBz2(BZ2 == null ? "":BZ2);
				cyyjpz.setBz3(BZ3 == null ? "":BZ3);
				cyyjpz.setBz4(BZ4 == null ? "":BZ4);
				
				cyyjpzService.saveCyyjpz(cyyjpz);
		 returnJSONView(AjaxHelper.toJSON(cyyjpz, AjaxHelper.SUCCESS, "新增常用意见成功"));
	 }catch (Exception e) 
	 	{
			e.printStackTrace();
			logger.error("CyyjpzController.saveCyyjpz:", e);
			returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.FAILURE, e.getMessage()));
		}
	 }
	 
	 /**
	  * 修改常用意见数据
	  * @throws IOException
	  */
		 @RequestMapping("/updateCyyjpz")
		 public void updateCyyjpz() throws IOException
		 {
			 try{
					
				 Map<String, String>  paramsMap =  this.getParamsMap();
				 String id = paramsMap.get("ID");
					if(StringUtils.isEmpty(id))
					{
						returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.FAILURE, "缺少主键ID"));
						return;
					}
					 Cyyjpz cyyjpz=cyyjpzService.queryCyyjpzById(Long.parseLong(id));
					 	String YWLXID = paramsMap.get("YWLXID");
						String YWLXMC = paramsMap.get("YWLXMC");
						String MS = paramsMap.get("MS");
						String QT = paramsMap.get("QT");
						String CYYJ = paramsMap.get("CYYJ");
						String SYZID = paramsMap.get("SYZID");
						String SZJDID = paramsMap.get("SZJDID");
						String JDMC = paramsMap.get("JDMC");
						String CJR = paramsMap.get("CJR");
						String CJRMC = paramsMap.get("CJRMC");
						String ZHXGR = paramsMap.get("ZHXGR");
						String ZHXGRMC = paramsMap.get("ZHXGRMC");
						String BZ1 = paramsMap.get("BZ1");
						String BZ2 = paramsMap.get("BZ2");
						String BZ3 = paramsMap.get("BZ3");
						String BZ4 = paramsMap.get("BZ4");
						
						cyyjpz.setYwlxid(YWLXID ==null ? cyyjpz.getYwlxid(): YWLXID);
						cyyjpz.setYwlxmc(YWLXMC ==null ? cyyjpz.getYwlxmc(): YWLXMC);
						cyyjpz.setMs(MS ==null ? cyyjpz.getMs(): MS);
						cyyjpz.setQt(QT ==null ? cyyjpz.getQt(): QT);
						cyyjpz.setCyyj(CYYJ ==null ? cyyjpz.getCyyj(): CYYJ);
						cyyjpz.setSyzid(SYZID ==null ? cyyjpz.getSyzid(): SYZID);
						cyyjpz.setSzjdid(SZJDID ==null ? cyyjpz.getSzjdid(): SZJDID);
						cyyjpz.setJdmc(JDMC ==null ? cyyjpz.getJdmc(): JDMC);
						cyyjpz.setCjr(CJR == null ? cyyjpz.getCjr():CJR);
						cyyjpz.setCjrmc(CJRMC == null ? cyyjpz.getCjrmc():CJRMC);
						cyyjpz.setZhxgr(ZHXGR == null ? cyyjpz.getZhxgr():ZHXGR);
						cyyjpz.setZhxgrmc(ZHXGRMC == null ? cyyjpz.getZhxgrmc():ZHXGRMC);
						cyyjpz.setSfhf(1);
						cyyjpz.setBz1(BZ1 == null ? cyyjpz.getBz1():BZ1);
						cyyjpz.setBz2(BZ2 == null ? cyyjpz.getBz2():BZ2);
						cyyjpz.setBz3(BZ3 == null ? cyyjpz.getBz3():BZ3);
						cyyjpz.setBz4(BZ4 == null ? cyyjpz.getBz4():BZ4);
					
			 
						cyyjpzService.updateCyyjpz(cyyjpz);
						returnJSONView(AjaxHelper.toJSON(cyyjpz, AjaxHelper.SUCCESS, "更新"));
		 }catch (Exception e) 
		 	{
				e.printStackTrace();
				logger.error("CyyjpzController.saveCyyjpz:", e);
				returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.FAILURE, e.getMessage()));
			}
		 }
		 
		 
		 /**
		  * 刪除常用意見
		  * @throws IOException
		  */
		 @RequestMapping("/deleteCyyjpz")
			public void deleteCyyjpz() throws IOException
			{
				try{
					Map<String, String> paramsMap = this.getParamsMap();
					String id = paramsMap.get("ID");
					if(null == id)
					{
						returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.FAILURE, "缺少主键ID"));
						return;
					}
					
					cyyjpzService.deleteCyyjpz(Long.parseLong(id));
					returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.SUCCESS, "删除表单仓库数据！"));
					
				}catch (Exception e) {
					e.printStackTrace();
					logger.error("CyyjpzController.saveCyyjpz:", e);
					returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.FAILURE, e.getMessage()));
				}
			}
		 
		 /**
		  * 查詢常用意見
		  * @throws IOException
		  */
		 @RequestMapping("/queryCyyjpz")
			public void queryCyyjpz() throws IOException {
				try {

					List<Map<String, String>> bdzhbList = cyyjpzService.queryCyyjpz();
							
					returnJSONView(AjaxHelper.toJSON(bdzhbList, AjaxHelper.SUCCESS,
							"表单组合数据查询！"));

				} catch (Exception e) {
					e.printStackTrace();
					logger.error("cyyjpzController.saveBdck:", e);
					returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.FAILURE,
							e.getMessage()));
				}
			}
		 
		 /**
		  * 按ID查询常用意见数据
		  * @throws IOException
		  */
		 @RequestMapping("/queryCyyjpzById")
			public void queryCyyjpzById() throws IOException
			{
			 try
				{
			 Map<String, String> paramsMap = this.getParamsMap();
				
				String ID = paramsMap.get("ID");
				if(StringUtils.isNumeric(ID)){
					returnJSONView(AjaxHelper.toJSON(cyyjpzService.queryCyyjpzById(Long.parseLong(ID)), AjaxHelper.SUCCESS, "查询成功"));
				}
					
				}catch (Exception e)
				{
					returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.FAILURE, e.getMessage()));
					logger.error(e.getMessage());
				}
			}
			
}
